package ooday03;

public class RefArrayDemo {
    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",1,"黄色");
        dogs[1] = new Dog("小白",2,"白色");
        dogs[2] = new Dog("小橙",1,"橙色");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for(int i=0;i<dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("大花",1,"花色");
        chicks[1] = new Chick("小花",2,"黄色");
        for(int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].layEggs();
        }

        Fish[] fish = new Fish[4];
        fish[0]=new Fish("小红",1,"红色");
        fish[1]=new Fish("小黄",2,"黄色");
        fish[2]=new Fish("小绿",2,"绿色");
        fish[3]=new Fish("小紫",3,"紫色");
        for(int i=0;i<fish.length;i++){
            System.out.println(fish[i].color);
            fish[i].swim();
        }

        /*
        Dog[] dogs = new Dog[3];
        dogs[0]=new Dog("小黑",2,"黑色");
        dogs[1]=new Dog("小白",1,"白色");
        dogs[2]=new Dog("小红",1,"红色");

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小花",1,"黄色");
        chicks[1] = new Chick("大花",2,"灰色");
        */
        /*
        //声明Dog型数组dogs,包含3个元素,每个元素都是Dog,默认值为null
        Dog[] dog = new Dog[3];
        //声明Chick型数组chicks,包含3个元素,每个元素都是Chick型,默认值为null
        Chick[] chicks = new Chick[3];
        //声明Fish型数组fish,包含2个元素,每个元素都是Fish型,默认值为null
        Fish[] fish = new Fish[2];
        */
    }
}
